package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.domain.StrategyTheme;
import cn.wolfcode.luowowo.query.StrategyThemeQuery;
import cn.wolfcode.luowowo.service.IDestinationService;
import cn.wolfcode.luowowo.service.IStrategyThemeService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("strategyTheme")
public class StrategyThemeController {

    @Autowired
    private IStrategyThemeService strategyThemeService;

    @Autowired
    private IDestinationService destinationService;

    //查询列表
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")StrategyThemeQuery qo){

        //pageInfo === mybais====mysql
        //page---spring-data---mongodb
        Page<StrategyTheme> page = strategyThemeService.query(qo);
        model.addAttribute("page",page);
        return "strategyTheme/list";
    }

    //保存和更新
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyTheme strategyTheme){

        //pageInfo === mybais====mysql
        //page---spring-data---mongodb
        strategyThemeService.saveOrUpdate(strategyTheme);
        return JsonResult.success();
    }

    //目的地查询
    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep){
        //pageInfo === mybais====mysql
        //page---spring-data---mongodb
        List<Destination> list = destinationService.list();
        return list;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        //通过id,和hot改变数据
        strategyThemeService.delete(id);
        return JsonResult.success();
    }



}
